import { useSelector } from 'react-redux'
import { StateType } from '../store'
import { ComponentStateType } from '../store/componentsReducer'

function useGetComponentInfo() {
  const {
    componentList = [],
    selectedId,
    copiedComponent,
  } = useSelector<StateType>(state => state.components.present) as ComponentStateType

  // 根据 selectedId 获取选中的组件
  const selectedComponent = componentList.find(c => c.fe_id === selectedId)

  return { componentList, selectedId, selectedComponent, copiedComponent }
}

export default useGetComponentInfo
